package 面向对象中级.继承;

public class Test03 {

    //游戏：人+枪，人可能拿着枪，打战
    public static void main(String[] args) {
        ShiBing shiBing = new ShiBing();
        shiBing.name="冷锋";
        shiBing.kaihuo();//冷风,去捡起那个该死的枪！！
        ShouQiang shouQiang = new ShouQiang();//创建一把枪
        shiBing.jianQiang(shouQiang);
        shiBing.kaihuo();//biu~~~biu~~~biu~~~
        JiGuanQiang jiGuanQiang=new JiGuanQiang();
        shiBing.jianQiang(jiGuanQiang);
        shiBing.kaihuo();//哒哒哒
        FaLingQaing faLingQaing=new FaLingQaing();
        shiBing.jianQiang(faLingQaing);
        shiBing.kaihuo();
    }
}
//soldiers
class ShiBing{//士兵
    public String name;
    public Qiang qiang;

    public void jianQiang(Qiang qiang){
        this.qiang=qiang;
    }

    public void kaihuo(){
        if(qiang!=null){
            qiang.kai();
        }else{
            System.out.println(name+",去捡起那个该死的枪！！");
        }
    }
}
//向上转型：子类===>父类
class Qiang{//父类
    public void kai(){
        //???这里不用写任何代码
    }
}

class ShouQiang extends Qiang{//手枪
    public void kai(){
        System.out.println("biu~~~biu~~~~biu~~~");
    }
}

class JiGuanQiang extends  Qiang{//机关枪
    public void kai(){
        System.out.println("哒哒哒~~~哒哒哒~~~哒哒哒~~~");
    }
}

class FaLingQaing extends Qiang{//发令枪
    public void kai(){
        System.out.println("噗~~~噗~~~噗~~~");
    }
}


